
//--> Loth 2011 
//--> Auto skybox see scripte in fla/sky.fla

package chamans.away
{
	import away3d.cameras.*;
	import away3d.containers.*;
	import away3d.core.base.*;
	import away3d.entities.*;
	import away3d.events.LoaderEvent;
	import away3d.lights.*;
	import away3d.materials.*;
	import away3d.materials.methods.*;
	import away3d.materials.utils.CubeMap;
	import away3d.primitives.*;
	
	import chamans.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.ui.*;
	import flash.utils.*;
	public class sky extends Sprite{
		public function sky(base:Object, type:String, COLORS:Array ):void
		{
			BASE=base
			col=COLORS
			//[ 0xFF, 0x55, 0x00, 0x94846B, 400, 1, .8, true ]
			size=512; Pinch=200
			if(col[5]==1){size=1024; Pinch=380}
			if(col[5]==2){size=2048; Pinch=650}
			
			Type=type;
			taille=BASE.view.camera.lens.far

			MAT= new Vector.<BitmapMaterial>
			BIM= new Vector.<BitmapData>
			CIM= new Vector.<BitmapData>
				
			if (type=='vector')BASE.LOAD.SWF("assets/sky.swf", ['SKY'], create )
            // you can load image 
			else BASE.LOAD.IMGLIST(type, ['p1', 'p2', 'p3','p4', 'p5', 'p6' ], create, ".jpg" )
		} 
	
		internal function create(m:Array):void
		{
			var i:int
			var planmap:MovieClip
			if(Type=='vector'){
				planmap=new m[0]();
			 	planmap.define( size , col, Pinch )
			}
		
			// matiere
		    for (i=0;i<6;++i){
				if(Type=='vector'){
					BIM.push(BASE.TOOL.bit(planmap.full['v'+(i+1)], size, size, 1, false));
					CIM.push(BASE.TOOL.bit(BIM[i], size, size, .5, false));
				}
				else 	BIM.push(m[i])
				MAT.push(new BitmapMaterial(BIM[i]))
			} 
			
			// Away skyBox
			envMap=new CubeMap(CIM[0],CIM[1],CIM[4],CIM[5],CIM[2],CIM[3])
			envMap2=new CubeMap(BIM[0],BIM[1],BIM[4],BIM[5],BIM[2],BIM[3])
				
			BASE.view.scene.addChild(new SkyBox(envMap2));
			
			// My Box
		/*	SKYBOX = new ObjectContainer3D();
			var Cube:Object=new Object()
			O.view.scene.addChild(SKYBOX)
			for( i=0;i<6;i++){
				Cube["p"+i]=new Plane(MAT[i], taille, taille, 1, 1)
				if(i==0) Cube["p"+i].z=taille>>1
				else if(i==1){ Cube["p"+i].z=-taille>>1; Cube["p"+i].rotationX=180; Cube["p"+i].rotationZ=180;}
				else if(i==2){ Cube["p"+i].x=-taille>>1; Cube["p"+i].rotationY=-90;}
				else if(i==3){ Cube["p"+i].x=taille>>1; Cube["p"+i].rotationY=90;}
				else if(i==4){ Cube["p"+i].y=taille>>1; Cube["p"+i].rotationX=90;}
				else { Cube["p"+i].y=-taille>>1; Cube["p"+i].rotationX=-90;}
				SKYBOX.addChild(Cube["p"+i]);
			}*/
		}
		
	 	public var envMap:CubeMap;
		private var envMap2:CubeMap;
		internal var Type:String;
		internal var BIM:Vector.<BitmapData>;
		internal var CIM:Vector.<BitmapData>;
		internal var MAT:Vector.<BitmapMaterial>;
		internal var BASE:Object;
		internal var taille:int=20000;
		internal var col:Array;
		internal var size:int;
		internal var Pinch:int;
		private var LL:load
//END
}}